package com.xiaotao.service;

import com.xiaotao.util.WsUserSession;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class WebSocketPushService {
    @Resource
    private SimpMessagingTemplate template;

    @Resource
    private WsUserSession registry;

    public void sendOrderMsg(Integer userId, Object msg)
    {
        String sessionId = registry.getSessionId(String.valueOf(userId));
        if (sessionId != null) {
            template.convertAndSendToUser(String.valueOf(userId), "/queue/order", msg);
        }
    }
}
